package org.come.Jpanel;

import com.tool.btn.ChooseLhBtn;
import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.LiangHaoBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.RichLabel;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;
import org.apache.commons.lang.StringUtils;
import org.come.bean.LoginResult;
import org.come.until.CutButtonImage;
import org.come.until.FormsManagement;
import org.come.until.SrcollPanelUI;

import javax.swing.*;
import java.awt.*;
import java.lang.reflect.Field;
import java.util.List;

public class MyLiangHaoJpanel extends JPanel {

    private LiangHaoBtn openLiangHao,//开通靓号
            colorLiangHao,// 靓号染色
            btnbottomset,//频道显示
            andtime, dropBtn;    //续费

    private JLabel lianghaoexpire, oldid;      //过期时间
    private LiangHaoBtn lhBtn;

    public MyLiangHaoJpanel() {
        String style = MyIsif.getStyle();
        if (MyIsif.getStyle().equals("水墨UI")) {
            this.setPreferredSize(new Dimension(399, 396));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/button/1.png", 1, 640);
            offBtn.setBounds(399 - 34, 6, 25, 25);
            this.add(offBtn);

//        openLiangHao = new LiangHaoBtn("inkImg/newbutton/B22.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "开通靓号", 1, this);
//        this.openLiangHao.setBounds(255, 250, 100, 24);
//        this.add(this.openLiangHao);

            colorLiangHao = new LiangHaoBtn("inkImg/newbutton/B22.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "靓号染色", 2, this);
            this.colorLiangHao.setBounds(255, 292, 100, 24);
            this.add(this.colorLiangHao);

            btnbottomset = new LiangHaoBtn("inkImg/newbutton/B22.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "炼化属性", 6, this);
            this.btnbottomset.setBounds(255, 335, 100, 24);
            this.add(this.btnbottomset);

            andtime = new LiangHaoBtn("inkImg/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "续费", 4, this);
            this.andtime.setBounds(255, 185, 59, 24);
            andtime.setVisible(false);
            this.add(andtime);

            dropBtn = new LiangHaoBtn("inkImg/newbutton/B30.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "捐献", 5, this);
            this.dropBtn.setBounds(325, 185, 45, 24);
            dropBtn.setFont(UIUtils.TEXT_FONT11);
            dropBtn.setColors(UIUtils.COLOR_WHITE);
            dropBtn.setVerticalTextPosition(SwingConstants.CENTER);
            dropBtn.setHorizontalTextPosition(SwingConstants.CENTER);
            dropBtn.setVisible(false);
            this.add(dropBtn);

            oldid = new JLabel();
            oldid.setBounds(60, 55, 220, 15);
            oldid.setForeground(Color.WHITE);
            oldid.setFont(new Font("宋体", 0, 14));
            this.add(oldid);

            lianghaoexpire = new JLabel();
            lianghaoexpire.setBounds(60, 190, 220, 15);
            lianghaoexpire.setForeground(Color.WHITE);
            lianghaoexpire.setFont(new Font("宋体", 0, 12));
            this.add(lianghaoexpire);
        } else {
            this.setPreferredSize(new Dimension(399, 396));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            FormsOnOffBtn offBtn = new FormsOnOffBtn("img/xy2uiimg/8_jpg.button.btn_close.jpg", 1, 640);
            offBtn.setBounds(400 - 20, 2, 25, 25);
            this.add(offBtn);

//        openLiangHao = new LiangHaoBtn("inkImg/newbutton/B22.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "开通靓号", 1, this);
//        this.openLiangHao.setBounds(255, 250, 100, 24);
//        this.add(this.openLiangHao);

            colorLiangHao = new LiangHaoBtn("inkImg/hongmu/100_26.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, "靓号染色", 2, this);
            this.colorLiangHao.setBounds(255, 292, 100, 24);
            this.add(this.colorLiangHao);

            btnbottomset = new LiangHaoBtn("inkImg/hongmu/100_26.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, "炼化属性", 6, this);
            this.btnbottomset.setBounds(255, 335, 100, 24);
            this.add(this.btnbottomset);

            andtime = new LiangHaoBtn("inkImg/hongmu/60_26.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, "续费", 4, this);
            this.andtime.setBounds(255, 185, 59, 24);
            andtime.setVisible(false);
            this.add(andtime);

            dropBtn = new LiangHaoBtn("inkImg/hongmu/21_png.button.tab_nex.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, "捐献", 5, this);
            this.dropBtn.setBounds(325, 185, 45, 24);
            dropBtn.setFont(UIUtils.TEXT_FONT11);
            dropBtn.setColors(UIUtils.COLOR_WHITE);
            dropBtn.setVerticalTextPosition(SwingConstants.CENTER);
            dropBtn.setHorizontalTextPosition(SwingConstants.CENTER);
            dropBtn.setVisible(false);
            this.add(dropBtn);

            oldid = new JLabel();
            oldid.setBounds(60, 55, 220, 15);
            oldid.setForeground(Color.WHITE);
            oldid.setFont(new Font("宋体", 0, 14));
            this.add(oldid);

            lianghaoexpire = new JLabel();
            lianghaoexpire.setBounds(60, 190, 220, 15);
            lianghaoexpire.setForeground(Color.WHITE);
            lianghaoexpire.setFont(new Font("宋体", 0, 12));
            this.add(lianghaoexpire);
        }
    }

    private ImageIcon icon;

    private ImageIcon icon1;

    @Override
    protected void paintComponent(Graphics g) {
        String style = MyIsif.getStyle();
        if (MyIsif.getStyle().equals("水墨UI")) {
            super.paintComponent(g);
            if (icon == null)
                icon = new ImageIcon("inkImg/newbackground/MyLiangHao.png");
            // 背景
            g.drawImage(icon.getImage(), 0, 0, 399, 396, this);

            final LoginResult login = RoleData.getRoleData().getLoginResult();
            if (login.getLianghaoexpire() != null) {
                lianghaoexpire.setText("靓号到期时间：" + login.getLianghaoexpire());
                lianghaoexpire.setVisible(true);
                dropBtn.setVisible(true);
                andtime.setVisible(true);

            } else {
                lianghaoexpire.setVisible(false);
                dropBtn.setVisible(false);
                andtime.setVisible(false);

            }
            oldid.setText("原始ID：" + login.getRole_id());
            String num = login.getLiangHao();
            Integer type = login.getLianghaotype() == null ? 0 : login.getLianghaotype();
            if (StringUtils.isNotEmpty(num)) {
                String[] nums = num.split("");
                for (int j = 0; j < nums.length; j++) {
                    int xnum = 175 + (11 * j);
                    int ynum = 110;
                    g.drawImage(CutButtonImage.getImage("inkImg/number/" + String.valueOf(type) + nums[j] + ".png", 11, 15).getImage(), xnum, ynum, 11, 15, this);
                }
            }
        } else {
            super.paintComponent(g);
            if (icon == null)
                icon = new ImageIcon("img/xy2uiimg/lianghaoA.png");
            // 背景
            g.drawImage(icon.getImage(), 0, 0, 399, 396, this);

            final LoginResult login = RoleData.getRoleData().getLoginResult();
            if (login.getLianghaoexpire() != null) {
                lianghaoexpire.setText("靓号到期时间：" + login.getLianghaoexpire());
                lianghaoexpire.setVisible(true);
                dropBtn.setVisible(true);
                andtime.setVisible(true);

            } else {
                lianghaoexpire.setVisible(false);
                dropBtn.setVisible(false);
                andtime.setVisible(false);

            }
            oldid.setText("原始ID：" + login.getRole_id());
            String num = login.getLiangHao();
            Integer type = login.getLianghaotype() == null ? 0 : login.getLianghaotype();
            if (StringUtils.isNotEmpty(num)) {
                String[] nums = num.split("");
                for (int j = 0; j < nums.length; j++) {
                    int xnum = 175 + (11 * j);
                    int ynum = 110;
                    g.drawImage(CutButtonImage.getImage("inkImg/number/" + String.valueOf(type) + nums[j] + ".png", 11, 15).getImage(), xnum, ynum, 11, 15, this);
                }
            }
        }
    }

    public void showBox(String type, Object object, String text) {
//        this.type = type;
//        this.object = object;
//        if (richLabel == null) {
//            richLabel = new RichLabel(text, UIUtils.TEXT_NAME_FONT, 454);
//        } else {
//            richLabel.setTextSize(text, 454);
//        }
        FormsManagement.showForm(104);
    }

}
